import { DEFAULT_PAGE_CONFIG } from '@/constants/global.const';
import type { ParamsType } from '@ant-design/pro-provider';
import type { ProTableProps } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import React from 'react';

/**
 *
 * 基础的ProTable组件
 */
const CommonProTable: React.FC<ProTableProps<Record<string, any>, ParamsType, string>> = ({
  pagination,
  search,
  ...restProps
}) => (
  <ProTable
    bordered={false}
    tableLayout="fixed"
    cardBordered={false}
    options={false}
    revalidateOnFocus={false}
    size="small"
    pagination={
      (pagination || typeof pagination === 'undefined') && {
        size: 'default',
        showQuickJumper: false,
        showSizeChanger: true,
        showTotal: (total) => `共 ${total} 条`,
        pageSizeOptions: ['10', '20', '50', '100'],
        ...DEFAULT_PAGE_CONFIG,
        ...pagination,
      }
    }
    // 检索相关配置
    search={
      (search || typeof search === 'undefined') && {
        // span: { xs: 24, sm: 12, md: 8, lg: 8, xl: 8, xxl: 6 },
        // labelWidth: 'auto',
        // collapseRender: false,
        // defaultCollapsed: false,
        ...search,
      }
    }
    {...restProps}
  />
);

export default CommonProTable;
